save yourself from regex-whackamole🤞:
nlp(entireNovel).sentences().if('the #Adjective of times').out()
move things around:
nlp('she sells seashells by the seashore.').sentences().toFutureTense().out()
respond to text input:
if( doc.has('^simon says (shoot|fire) #Determiner lazer') ){
fireLazer()
} else {
dontFire()
}
<script src>
|
🙏
npm install compromise
|
|
IE9+
caniuse, youbetcha
|
⚡️ on the Client-side
<script src="https://unpkg.com/compromise@latest/builds/compromise.min.js"></script>
<script>
var doc = nlp('dinosaur')
var str = doc.nouns().toPlural().out('text')
console.log(str)
</script>
🌋 Server-side!
var nlp = require('compromise')
var doc = nlp('London is calling')
doc.sentences().toNegative()
Get the hang of things:
Input → output
|
Match & transform
|
Making a bot
|
Detailed docs:
Examples:
nouns! verbs! adjectives!
|
people, places, organizations
|
seven hundred and fifty == 750
|
like a regex for a sentence
|
all your base are belong
|
case, whitespace, contractions..
|
doc = nlp('a bottle of beer on the wall.')
doc.nouns(0).toPlural()
doc.out('text')
doc = nlp('ninety five thousand and fifty two')
doc.values().toNumber().out()
doc = nlp('the 23rd of December')
doc.values().add(2).toText()
doc.out('text')
doc = nlp("the guest-singer's björk at seven thirty.").normalize().out('text')
- Tense: - switch to/from conjugations of any verb
let doc = nlp('she sells seashells by the seashore.')
doc.sentences().toFutureTense().out('text')
doc.verbs().conjugate()
doc = nlp("we're not gonna take it, no we ain't gonna take it.")
doc.has('going')
doc.match('are not').length
doc.contractions().expand().out()
doc = nlp('the opera about richard nixon visiting china')
doc.topics().data()
var lexicon={
'boston': 'MusicalGroup'
}
doc = nlp('i heard Boston\'s set in Chicago', lexicon)
doc.match('heard #Possessive set').terms(1).tag('MusicalGroup')
doc = nlp('We like Roy! We like Roy!').sentences().out('array')
doc = nlp('Tony Hawk').out('html')
- Plugins: - allow adding vocabulary, fixing errors, and setting context quickly:
var plugin = {
tags:{
Character:{
isA: 'Noun'
}
},
words:{
itchy: 'Character',
scratchy: 'Character'
}
}
nlp.plugin(plugin)
nlp(`Couldn't Itchy share his pie with Scratchy?`).debug()
Join in -
we're fun, using semver, and moving fast:
☂️ Isn't javascript too...
💃 Can it run on my arduino-watch?
🌎 Other Languages?
✨ Partial builds?
Also:
For the former promise-library, see jnewman/compromise
(Thanks Joshua!)